package LeetCode.month01.day20;

import java.util.Arrays;

public class No643 {
    public static void main(String[] args) {
        System.out.println(findMaxAverage(new int[]{1,12,-5,-6,50,3},4));
    }
    public static double findMaxAverage(int[] nums, int k) {
        double sum = 0;
        int left = 0;
        int n = nums.length;
        int right = 0;
        while(right<k){
            sum+=nums[right];
            right++;
        }
        double max = sum;
        while(right<n){
            sum=sum+nums[right]-nums[left];
            max = Math.max(sum,max);
            left++;
            right++;
        }
        return max/k;
    }
}
